/**
* @file 充值中心
* @author 张超
* @created 2023/7/06 08:00
* @updated 2023/7/06 18:00
*/
<template>
	<view class="recharge_item">
		<view class="recharge_mouy">
			<view class="mouy-title">充值金额</view>
			<view class="mouy-titledes">用于直购商城消费</view>
			<ul>
				<li v-for="(item,index) in moneyList" :key="index" @click="select(item,index)"
					:class="current==index?'active':''">
					<view>
						<text>{{item.integral}}</text>
						<text>积分</text>
					</view>
					<view>¥{{item.money}}</view>
				</li>
			</ul>
		</view>
		<view class="recharge-zhif">
			<view>选择支付方式</view>
			<u-radio-group v-model="value" @change="radioGroupChange" v-for="(item, index) in list" :key="index">
				<view>
					<image src="@/static/index/index-bg.png"></image>
					<text>支付宝</text>
				</view>
				<u-radio @change="radioChange" :name="item.name" :disabled="item.disabled">
				</u-radio>
			</u-radio-group>
		</view>

		<view class="recharge_btn" @click="priceCommitRe">确认</view>
	</view>
</template>

<script>
	import {
		priceCommit
	} from '@/network/api.js'
	export default {
		props: {
			cuindex: {
				type: Number, //定义传值类型
				default: 0
			},
			orderItem: {
				type: Object,
				default: () => {}
			}
		},
		data() {
			return {
				current: 0,
				list: [{
						name: 'banner',
						disabled: false
					},
					{
						name: 'orange',
						disabled: false
					}
				],
				moneyList: [],
				objectwqe: {},
				value: 'orange',
				// 选中金额
				item:{},
				// 当前栏id
				id:''
			}
		},
		watch: { //监听事件，当mag值发生改变时，就会触发下面的函数
			orderItem: function(val) { //val表示修改后的内容
				this.objectwqe = JSON.parse(val.json)
				this.id=val.id
				this.ozhuanz()
			}
		},
		methods: {
			// 对象转数组
			ozhuanz() {
				let arr = [];
				for (let key in this.objectwqe) {
					arr.push({
						money: this.objectwqe[key], // label 字段
						integral: key, // value字段
					});
				}
				this.moneyList = arr
			},
			select(item,index) {
				this.current = index
				this.item=item
			},
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				// console.log(e);
			},
			// 提交订单——充值中心
			priceCommitRe() {
				let data={
					score:this.item.integral,
					money:this.item.money,
					typeid:this.id
				}
				console.log(data,'参数')
				// 获取交易配置数据
				// priceCommit(data).then(res => {
				// 	if (res.code == 1) {
				// 		console.log(res,'提交')
				// 	}
				// })
			},
		}
	}
</script>

<style lang="scss">
	.recharge_item {
		margin-top: 20rpx;

		.recharge_mouy {
			padding: 40rpx 20rpx;
			margin-bottom: 20rpx;
			border-radius: 20rpx;
			background-color: #ffffff;

			.mouy-title {
				font-size: 30rpx;
				font-family: PingFang SC, PingFang SC-Bold;
			}

			.mouy-titledes {
				font-size: 24rpx;
				color: #999999;
				margin-top: 20rpx;
				font-family: PingFang SC, PingFang SC-Medium;
			}

			>ul {
				display: flex;
				flex-wrap: wrap;
				margin-top: 20rpx;
				justify-content: space-between;

				.active {
					border: 1rpx solid #B27715;
					background-color: #FFEFCB;
				}

				>li {
					display: flex;
					flex-direction: column;
					width: 30%;
					height: 112rpx;
					text-align: center;
					line-height: 112rpx;
					padding: 20rpx 10rpx;
					margin-bottom: 20rpx;
					border-radius: 20rpx;
					box-sizing: border-box;
					border: 1rpx solid #EAEAEA;

					>view:nth-child(1) {
						height: 36rpx;
						line-height: 36rpx;
						margin-bottom: 12rpx;
						font-family: PingFang SC, PingFang SC-Medium;

						>text:nth-child(1) {
							font-size: 44rpx;
						}

						>text:nth-child(2) {
							font-size: 20rpx;
						}
					}

					>view:nth-child(2) {
						height: 17rpx;
						line-height: 17rpx;
						font-size: 22rpx;
						margin-top: 10rpx;
						font-family: PingFang SC, PingFang SC-Medium;
					}
				}

				// >li:last-child:nth-child(3n - 1) {
				// 	margin-right: calc(33.33% + 4% / 3);
				// }

				// /* 如果最后一行是2个元素 */
				// >li:last-child:nth-child(3n - 2) {
				// 	margin-right: calc(60% + 8% / 3);
				// }
			}
		}

		.recharge-zhif {
			height: 300rpx;
			padding: 40rpx 20rpx;
			border-radius: 20rpx;
			background-color: #fff;

			>view:nth-child(1) {
				font-size: 30rpx;
				font-family: PingFang SC, PingFang SC-Bold;
			}

			.u-radio-group {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 34rpx 0;

				>view:nth-child(1) {
					display: flex;
					align-items: center;

					>image {
						width: 36rpx;
						height: 36rpx;
						margin-right: 20rpx;
					}
				}

				.u-radio {
					margin-left: auto;
				}
			}
		}

		.recharge_btn {
			width: 690rpx;
			height: 90rpx;
			text-align: center;
			line-height: 90rpx;
			margin: 0 auto;
			margin-top: 100rpx;
			font-size: 36rpx;
			color: #fff;
			font-family: PingFang SC, PingFang SC-Medium;
			background: linear-gradient(0deg, #b07412 0%, #e3ba5b 100%);
			border-radius: 4px;
		}

		.recharge_btn:active {
			background: linear-gradient(0deg, #e3ba5b 0%, #e3ba5b 100%);
		}

	}
</style>